<template>
  <div>
    <van-nav-bar title="账号登录" left-arrow @click-left="onClickLeft" />
    <!-- form表单 -->
    <van-form @submit="onSubmit">
      <van-field v-model="username" name="username" placeholder="请输入账号" />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit">登 录</van-button>
      </div>
    </van-form>
    <!-- 前往注册 -->
    <div class="link">
      <router-link to="/login">还没有账号?前往注册</router-link>
    </div>
  </div>
</template>

<script>
import { LoginIn } from '@/api/user'
export default {
  name: '',
  components: {},
  props: {},
  data() {
    return {
      username: '',
      password: ''
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    onClickLeft() {},
    async onSubmit(values) {
      if (this.username.trim() === '' || this.password.trim() === '') {
        return this.$toast.fail('内容不能为空')
      }
      //   console.log('submit', values)
      const res = await LoginIn(values)
      console.log(res)
      if (res.status !== 200) {
        return this.$toast.fail(res.description)
      }
      this.$toast.success(res.description)
      this.$router.push('/home')
      //   this.$toast.success('登录成功')
      //   this.$router.push('/article')
    }
  }
}
</script>

<style scoped lang="less">
.van-form {
  padding-top: 25px;
  .van-button--info {
    margin-top: 30px;
    background-color: #21b97a;
    font-size: 18px;
  }
  .van-field {
    font-size: 18px;
    width: 345px;
    height: 56px;
    padding: 10px, 0;
  }
}
.link {
  color: #069;
  font-size: 12px;
  width: 100%;
  text-align: center;
}
</style>
